export function sum(a: number, b: number): number {
  return a + b
}
export type EnsureArray<T> = T extends null | undefined
  ? never
  : T extends Array<infer P>
  ? P
  : T

export function ensureArray(source?: null): never[]
export function ensureArray<T>(source: T): EnsureArray<T>
export function ensureArray(source: any): Array<any> {
  if (source === null) return []
  return Array.isArray(source) ? source : [source]
}

const data = ensureArray(null)
console.log('🚀 ~ data:', data)
const data2 = ensureArray([1, 2])
console.log('🚀 ~ data2:', data2)
const data3 = ensureArray(1)
console.log('🚀 ~ data3:', data3)
